#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
    int calPoints(vector<string>& operations) {
        vector<int> ret;
        for(auto& s:operations)
        {
            int n=ret.size();
            if(s=="D")
                ret.push_back(ret[n-1]*2);
            else if(s=="C")
                ret.pop_back();
            else if(s=="+")
                ret.push_back(ret[n-1]+ret[n-2]);
            else ret.push_back(stoi(s));
        }
        int sum=0;
        for(int i=0;i<ret.size();i++) sum+=ret[i];
        return sum;
    }
};
